using System;
using System.Collections;
using System.Collections.Generic;
using Main.Details;
using Main.Event;
using UnityEngine;
using ZSW.Framework;

namespace Main.NPC
{
    public class NPCManager : ZSWF_Singleton<NPCManager>
    {
        public SceneRouteDataList_SO sceneRouteData;
        public List<NPCPosition> positions;
        private Dictionary<string, SceneRoute> sceneRouteDict = new Dictionary<string, SceneRoute>();

        public override void Init()
        {
            base.Init();
            InitSceneRouteDict();

            MainEventSystem.StartNewGameEvent += OnStartNewGame;
        }

        private void OnStartNewGame(int obj)
        {
            foreach (var character in positions)
            {
                character.npc.position = character.position;
                character.npc.GetComponent<NPCMovement>().StartScene = character.starScene;
            }
        }

        private void InitSceneRouteDict()
        {
            if (sceneRouteData.SceneRouteList.Count > 0)
            {
                foreach (var sceneRoute in sceneRouteData.SceneRouteList)
                {
                    sceneRouteDict.Add(sceneRoute.sceneName + sceneRoute.gotoSceneName, sceneRoute);
                }
            }
        }

        public bool TryGetSceneRoute(string startScene, string endScene, out SceneRoute sceneRoute)
        {
            return sceneRouteDict.TryGetValue(startScene + endScene, out sceneRoute);
        }
    }
}